package top.sunpxit.generator.config;

import javax.sql.DataSource;

import java.math.BigDecimal;
import java.sql.*;


/**
 * @program: set-sail-generator
 * @description: 数据源配置类
 * @author: sunpx
 * @create: 2021-03-26 10:22
 **/
public class DataSourceConfig {

    private static Connection connection;

    private DataSourceConfig() {

    }

    /**
     * 初始化数据库
     *
     * @param driver
     * @param url
     * @param username
     * @param password
     * @return void
     * @author: sunpx
     * @date: 2021-03-26 11:23:34
     */
    public static void initDataSource(String driver, String url, String username, String password) throws SQLException, ClassNotFoundException {
        Class.forName(driver);
        connection = DriverManager.getConnection(url, username, password);
    }


    /**
     * 获取Connection对象
     *
     * @param
     * @return java.sql.Connection
     * @author: sunpx
     * @date: 2021-03-26 13:06:49
     */
    public static Connection getConnection() {
        if (connection == null) {
            throw new NullPointerException();
        }

        return connection;
    }
}
